﻿using AutoPrint.BJPT.BLL;
using AutoPrint.BJPT.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoPrint.BJPT
{
    public partial class History : Form
    {
        private EngineService engineService = new EngineService();
        public History()
        {
            InitializeComponent();
            DG_EunHis.AutoGenerateColumns = false;
        }

        private void Btn_Query_Click(object sender, EventArgs e)
        {
            var query_Eun = TB_Eun.Text.Trim();
            var query_Day = Convert.ToInt32(DTP_Day.Value.ToString("yyyyMMdd"));
            //Eun无输入
            if (string.IsNullOrEmpty(query_Eun))
            {
                //日期有输入
                if (query_Day > 20000000)
                {
                    var dataList = engineService.Load(query_Day);
                    if (dataList.Count > 0)
                    {
                        DG_EunHis.DataSource = new BindingList<ENGINE>(dataList);
                    }
                    else
                    {
                        DG_EunHis.DataSource = new BindingList<ENGINE>();
                        MessageBox.Show("未检索到数据");
                    }
                }
                else
                {
                    MessageBox.Show("请输入查询条件后重试");
                }
            }
            else
            {
                var dataList = engineService.Load(query_Eun);
                if (dataList.Count > 0)
                {
                    DG_EunHis.DataSource = new BindingList<ENGINE>(dataList);
                }
                else
                {
                    DG_EunHis.DataSource = new BindingList<ENGINE>();
                    MessageBox.Show("未检索到数据");
                }
            }
        }
    }
}
